package com.wdh.kjs.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ScrollView;

import com.wdh.kjs.Adapter.InvestmentListAdapter;
import com.wdh.kjs.Adapter.InvestmentRecordAdapter;
import com.wdh.kjs.Adapter.ListViewForScrollView;
import com.wdh.kjs.R;
import com.wdh.kjs.activity.InvestManageActivity;
import com.wdh.kjs.activity.InvestmentDetailActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by cqh on 2016/3/7.
 */
public class InvestmentRecordFragment extends Fragment implements AdapterView.OnItemClickListener {
    private ListViewForScrollView investment_record_listview;
    private ScrollView investment_record_scrollview;
    private InvestmentRecordAdapter investmentRecordAdapter;
    private List<HashMap<String, String>> datas;
    private HashMap<String, String> maps = new HashMap<String, String>();
    private Intent intent;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_investmentrecord, container, false);
        initView(view);
        initwidge();
        return view;
    }

    private void initView(View view) {
        investment_record_listview = (ListViewForScrollView) view.findViewById(R.id.fragment_investmentrecord_listview);
        investment_record_scrollview = (ScrollView) view.findViewById(R.id.fragment_investmentrecord);
        investment_record_scrollview.smoothScrollTo(0, 0);

    }

    private void initwidge() {
        investmentRecordAdapter = new InvestmentRecordAdapter(getContext(), initListViewData());
        investment_record_listview.setAdapter(investmentRecordAdapter);
        investment_record_listview.setOnItemClickListener(this);
    }

    private List<HashMap<String, String>> initListViewData() {
        datas = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            HashMap<String, String> hashMap = new HashMap<>();
            hashMap.put("im_investment_type", "三农贷");
            hashMap.put("im_investment_name", "测试1号");
            hashMap.put("im_investment_scale", "10%");
            hashMap.put("im_investment_month", "90天");
            hashMap.put("im_investment_money", "￥100.00");
            hashMap.put("im_investment_state", "待确认");
            hashMap.put("im_investment_time", "2016/03/05");
            datas.add(hashMap);
        }
//        for (int i = 0; i < 2; i++) {
//            HashMap<String, String> hashMap = new HashMap<>();
//            hashMap.put("im_investment_type", "政信贷");
//            hashMap.put("im_investment_name", "测试1号");
//            hashMap.put("im_investment_scale", "10%");
//            hashMap.put("im_investment_month", "90天");
//            hashMap.put("im_investment_money", "￥100.00");
//            hashMap.put("im_investment_state", "已支付");
//            hashMap.put("im_investment_time", "2016/03/05");
//            datas.add(hashMap);
//        }
//        for (int i = 0; i < 2; i++) {
//            HashMap<String, String> hashMap1 = new HashMap<>();
//            hashMap1.put("im_investment_type", "三农贷");
//            hashMap1.put("im_investment_name", "测试2号");
//            hashMap1.put("im_investment_scale", "10%");
//            hashMap1.put("im_investment_month", "90天");
//            hashMap1.put("im_investment_money", "￥100.00");
//            hashMap1.put("im_investment_state", "订单失效");
//            hashMap1.put("im_investment_time", "2016/03/05");
//            datas.add(hashMap1);
//        }
        return datas;

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        maps = datas.get(position);
        intent = new Intent(this.getActivity(), InvestManageActivity.class);
        startActivity(intent);

    }
}
